﻿using ConfExpert.Forms.Base;

using DevTeam;

using System;
namespace ConfExpert.Forms.Destex.Satis
{
    public partial class CariHesap : XForm
    {
        public CariHesap()
        {
            InitializeComponent();
        }

        private void Cari_Load(object sender, EventArgs e)
        {
            GridMenu gm = GridManager.GetManager(gridView1).GridMenu;
            gm.AddMenu("Ödeme ekle", OdemeEkle);

            gridView1.Init("DX_GetOdeme");
            gridView1.AddDetailGrid(gridView2, "DX_MusteriId", 1); //satışlar

            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();
            gridView1.FormatAsNumber(1, "ToplamMetraj", "BakiyeTl", "AlacakTl");
            gridView2.FormatAsNumber(1, "ToplamMetraj", "BakiyeTl", "TutarTl", "OdenenTl");
            gridView1.AddSummary("ToplamMetraj", "BakiyeTl", "AlacakTl");
            gridView2.AddSummary("ToplamMetraj", "BakiyeTl", "TutarTl", "OdenenTl");

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            splitContainerControl1.AutoSize();

            btnGuncelle.ItemClick += btnGuncelle_ItemClick;
            gridView1.FocusedRowChanged += GridView1_FocusedRowChanged;
        }

        private void GridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void btnGuncelle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.RefreshDataSource("DX_GetOdeme");
            gridView1.BestFitColumns();
        }

        private void OdemeEkle(object sender, EventArgs e)
        {
            int musteriId = gridView1.GetFocusedRowCellValue("DX_MusteriId").ToInt();
            if (musteriId > 0)
                using (YeniOdeme yo = new YeniOdeme(musteriId))
                {
                    if (yo.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        btnGuncelle.PerformClick();
                        Notify("Ödeme başarıyla eklendi.");
                    }
                }
            else
                ShowMessage("Lütfen ödeme eklemek istediğiniz müşteriyi seçin.");
        }

    }
}
